﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="Order_NewReturnDoc"
    EnableEventValidation="false" Codebehind="NewReturnDoc.aspx.cs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <style type="text/css">
.menu_bg4 {background-color:#cccccc;text-align:left;margin:10px 0 10px 0;padding-top:5px;padding-bottom:5px;border:#CCCCCC 0px solid; font-size:12px;padding-left:20px;}
.jiacu { font-weight:bold;line-height:22px;}
.zt7 {text-align:right; color:#000000;}
.input_button6 {width:52px;height:23px;border:none;cursor:pointer; background:#ffffff url(../Include/Images/bt.gif) no-repeat;font-weight:bold;}
.td_left {border-left:#999999 1px solid; border-top:#999999 1px solid; border-bottom:#999999 1px solid; border-right:#999999 0px solid; font-weight:bold; background:#e7e7e7; text-align:center; line-height:22px;}
.td_right {border-left:#999999 1px solid; border-top:#999999 1px solid; border-bottom:#999999 1px solid; border-right:#999999 1px solid; font-weight:bold; background:#e7e7e7; text-align:center; line-height:22px;}
.td_left1 {border-left:#999999 1px solid; border-top:#999999 0px solid; border-bottom:#999999 1px solid; border-right:#999999 0px solid;  text-align:center; line-height:22px;}
.td_right1 {border-left:#999999 1px solid; border-top:#999999 0px solid; border-bottom:#999999 1px solid; border-right:#999999 1px solid;  text-align:center; line-height:22px;}
.td_left2 {border-left:#999999 1px solid; border-top:#999999 0px solid; border-bottom:#999999 1px solid; border-right:#999999 0px solid;  text-align:right; line-height:22px;}
.td_right2 {border-left:#999999 1px solid; border-top:#999999 0px solid; border-bottom:#999999 1px solid; border-right:#999999 1px solid;  text-align:right; line-height:22px;}    
</style>

    <script type="text/javascript">
    function urlred()
    {
        window.location.href="OrderList.aspx?ts=tui";
    }
    function CountTotal()
       {
           var rowCount = document.getElementById("hidOrderDetailCount").value;
           var totalQuantity = 0;
           var totalPrice = 0;
           var totalWeight = 0;
           for(var i=1;i<=rowCount;i++)
           {
                if(i<10)
                {
                    var quantityId = "DataList1_ctl0" + i + "_txtQuantity";
                    var oldQuantityId = "DataList1_ctl0" + i + "_txtOldQuantity";
                    var spriceId = "DataList1_ctl0" + i + "_lblSprice";
                    var hidSpriceId = "DataList1_ctl0" + i + "_hidSprice";
                    var discountId = "DataList1_ctl0" + i + "_lblDiscount";
                    var apriceId = "DataList1_ctl0" + i + "_lblAprice";
                    var hidApriceId = "DataList1_ctl0" + i + "_hidAprice";
                    var samtId = "DataList1_ctl0" + i + "_lblSamt";
                    var aamtId = "DataList1_ctl0" + i + "_lblAamt";
                    var weightId = "DataList1_ctl0" + i + "_lblWeight";
                    var hidWeightId = "DataList1_ctl0" + i + "_hidWeight";
                    
                    var quantity = document.getElementById(quantityId);
                    var oldQuantity = document.getElementById(oldQuantityId);
                    var sprice = document.getElementById(spriceId);
                    var hidSprice = document.getElementById(hidSpriceId);
                    var discount = document.getElementById(discountId);
                    var aprice = document.getElementById(apriceId);
                    var hidAprice = document.getElementById(hidApriceId);
                    var samt = document.getElementById(samtId);
                    var aamt = document.getElementById(aamtId);
                    var weight = document.getElementById(weightId);
                    var hidWeight = document.getElementById(hidWeightId);
                    
                    if(quantity.value*1.00>oldQuantity.value*1.00)
                    {
                        quantity.value = oldQuantity.value;
                        alert("退货数量不能大于订单原始数量！");
                        //return;
                    }
                    
                    var tempAprice =  hidSprice.value*discount.innerText;
                    //var tempSamt = quantity.value*hidSprice.value;
                    var tempSamt = quantity.value*sprice.innerText; 
                    var tempAamt = quantity.value*hidSprice.value*discount.innerText;
                    var tempWeight = quantity.value*hidWeight.value;
                    
                    aprice.innerText = tempAprice.toFixed(2);
                    samt.innerText = tempSamt.toFixed(2);
                    aamt.innerText = tempAamt.toFixed(2);
                    weight.innerText = tempWeight.toFixed(2);
                    
                    
                    
                    totalQuantity = totalQuantity*1.00 + quantity.value*1.00;
                    totalPrice = totalPrice*1.00 + aamt.innerText*1.00;
                    totalWeight = totalWeight*1.00 + weight.innerText*1.00;
                    
                }
                else
                {
                    var quantityId = "DataList1_ctl" + i + "_txtQuantity";
                    var oldQuantityId = "DataList1_ctl0" + i + "_txtOldQuantity";
                    var spriceId = "DataList1_ctl" + i + "_lblSprice";
                    var hidSpriceId = "DataList1_ctl" + i + "_hidSprice";
                    var discountId = "DataList1_ctl" + i + "_lblDiscount";
                    var apriceId = "DataList1_ctl" + i + "_lblAprice";
                    var hidApriceId = "DataList1_ctl" + i + "_hidAprice";
                    var samtId = "DataList1_ctl" + i + "_lblSamt";
                    var aamtId = "DataList1_ctl" + i + "_lblAamt";
                    var weightId = "DataList1_ctl" + i + "_lblWeight";
                    var hidWeightId = "DataList1_ctl" + i + "_hidWeight";
                    
                    var quantity = document.getElementById(quantityId);
                    var oldQuantity = document.getElementById(oldQuantityId);
                    var sprice = document.getElementById(spriceId);
                    var hidSprice = document.getElementById(hidSpriceId);
                    var discount = document.getElementById(discountId);
                    var aprice = document.getElementById(apriceId);
                    var hidAprice = document.getElementById(hidApriceId);
                    var samt = document.getElementById(samtId);
                    var aamt = document.getElementById(aamtId);
                    var weight = document.getElementById(weightId);
                    var hidWeight = document.getElementById(hidWeightId);
                    
                    if(quantity.value*1.00>oldQuantity.value*1.00)
                    {
                        quantity.value = oldQuantity.value;
                        alert("退货数量不能大于订单原始数量！");
                        //return;
                    }
                    
                    var tempAprice =  hidSprice.value*discount.innerText;
                    //var tempSamt = quantity.value*hidSprice.value;
                    var tempSamt = quantity.value*sprice.innerText; 
                    var tempAamt = quantity.value*hidSprice.value*discount.innerText;
                    var tempWeight = quantity.value*hidWeight.value;
                    
                    aprice.innerText = tempAprice.toFixed(2);
                    samt.innerText = tempSamt.toFixed(2);
                    aamt.innerText = tempAamt.toFixed(2);
                    weight.innerText = tempWeight.toFixed(2);
                    
                    totalQuantity = totalQuantity*1.00 + quantity.value*1.00;
                    totalPrice = totalPrice*1.00 + aamt.innerText*1.00;
                    totalWeight = totalWeight*1.00 + weight.innerText*1.00;
                    
                }
           }
           
//           var orderMainQuantity = document.getElementById("dlistOrderMain_ctl00_lblQuantity");
//           var orderMainAmt = document.getElementById("dlistOrderMain_ctl00_lblAmt");
//           var orderMainOfferAmt = document.getElementById("dlistOrderMain_ctl00_txtOfferAmt");
//           var orderMainTranCost = document.getElementById("dlistOrderMain_ctl00_txtTranCost");
           var orderMainAamt = document.getElementById("lblReturnTotal");
           var tranCost = document.getElementById("txtwlfy");
//           var orderMainWeight = document.getElementById("dlistOrderMain_ctl00_lblWeight");
//           var hidCity = document.getElementById("hidCity");
//           var dropTraner = document.getElementById("dlistOrderMain_ctl00_dropTraner");
           
//           orderMainQuantity.innerText = totalQuantity;
//           orderMainAmt.innerText = totalPrice.toFixed(2);
//           orderMainWeight.innerText = totalWeight.toFixed(2);
             var rangliCost=document.getElementById("txtRangLi").value;
            
            var totalAmount = totalPrice - tranCost.value*1.00 + rangliCost*1.00;
            orderMainAamt.innerText=totalAmount.toFixed(2);
//           var tranerCode = "";
//           for(var i=0;i<dropTraner.options.length;i++)
//           {
//               if(dropTraner.options[i].selected)
//               {
//                    tranerCode = dropTraner.options[i].value;
//                    break;
//               }
//           }
//           
//           if(hidCity.value=="")
//           {
//               return;
//           }           
//           
//           //异步计算物流费用
//           createRequest();
//           xmlhttp.onreadystatechange = StateDO;
//           xmlhttp.open("GET","CountTranCost.aspx?traner=" + tranerCode + "&city=" + hidCity.value + "&weight=" + totalWeight ,true);
//           xmlhttp.send(null);         
           
           
       }
    </script>

</head>
<body onload="CountTotal();">
    <form id="form1" runat="server">
        <div align="Justify">
            <h2>
                新增退货单<asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
            </h2>
            <div class="juli">
                <table style="background-color: #999999;" border="0" cellspacing="1" cellpadding="0">
                    <tr class="z2">
                        <td class="zt5" width="120">
                            退货原因：
                        </td>
                        <td width="200">
                            <asp:DropDownList ID="DropDownList2" Width="126" runat="server">
                            </asp:DropDownList>                            
                        </td>
                        <td class="zt5" width="120">
                            责任人：
                        </td>
                        <td width="200">
                            <asp:DropDownList ID="DropDownList3" Width="126" runat="server">
                            </asp:DropDownList>                            
                        </td>
                    </tr>                
                    <tr class="z2">
                        <td class="zt5" width="120">
                            关联订单：(*)
                        </td>
                        <td width="200">
                            <asp:TextBox ID="TextBox1" Width="120" runat="server"></asp:TextBox><input type="button"
                                class="input_button6" onclick="urlred();" value="..." />
                        </td>
                        <td class="zt5" width="120">
                            会员帐号：(*)
                        </td>
                        <td width="200">
                            <asp:Label ID="lblgmr" runat="server" Text=""></asp:Label>
                        </td>
                    </tr>
                    <tr class="z2">
                        <td class="zt5" width="120">
                            会员真实姓名：

                        </td>
                        <td width="200">
                            <asp:Label ID="lblRealName" runat="server" Text=""></asp:Label>
                        </td>
                        <td class="zt5" width="120">
                            会员昵称：

                        </td>
                        <td width="200">
                            <asp:Label ID="lblNickName" runat="server" Text=""></asp:Label>
                        </td>
                    </tr>
                    <tr class="z2">
                        <td class="zt5">
                            物流公司：

                        </td>
                        <td>
                            <asp:DropDownList ID="ddlwlfs" Width="126" runat="server">
                            </asp:DropDownList>
                        </td>
                        <td class="zt5">
                            退货人：(*)
                        </td>
                        <td>
                            <asp:TextBox ID="txtshr" Width="120" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr class="z2">
                        <td class="zt5">
                            物流费用：

                        </td>
                        <td>
                            <asp:TextBox ID="txtwlfy" CssClass="zt7" Width="120" Text="0" runat="server" onkeyup="CountTotal()"></asp:TextBox>
                        </td>
                        <td class="zt5">
                            退货人电话：

                        </td>
                        <td>
                            <asp:TextBox ID="txtshrdh" Width="120" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr class="z2">
                          <%-- <td class="zt5">
                         费用性质：

                        </td>
                        <td>
                           <asp:DropDownList ID="ddlfyxz" Width="126" runat="server" Enabled="false">
                                <asp:ListItem Text="卖方承担" Selected="true" Value="001"></asp:ListItem>
                                <asp:ListItem Text="买方承担"  Value="002"></asp:ListItem>
                            </asp:DropDownList>
                        </td>--%>
                        <td class="zt5">
                           让利金额：

                        </td>
                        <td>
                            <asp:TextBox ID="txtRangLi" CssClass="zt7" Width="120" Text="0" runat="server" onkeyup="CountTotal()"></asp:TextBox>
                        </td>
                        <td class="zt5">
                            退货人手机：

                        </td>
                        <td>
                            <asp:TextBox ID="txtshrsj" Width="120" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr class="z2">
                        <td class="zt5">
                            物流单号：

                        </td>
                        <td>
                            <asp:TextBox ID="txtwldh" Width="120" runat="server"></asp:TextBox>
                        </td>
                        <td class="zt5">
                            退货人邮编：

                        </td>
                        <td>
                            <asp:TextBox ID="txtshryb" Width="120" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr class="z2">
                        <td class="zt5">
                            商品总金额：
                        </td>
                        <td>
                            <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
                        </td>
                        <td class="zt5">
                            退货人地址：

                        </td>
                        <td>
                            <asp:TextBox ID="txtshrdz" Width="120" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr class="z2">
                        <td class="zt5">
                            订单总金额：
                        </td>
                        <td>
                            <asp:Label ID="Label3" runat="server" Text=""></asp:Label>
                        </td>
                        <td class="zt5">
                           备注：
<span style="display:none;"><asp:Label ID="Label4" runat="server" Text=""></asp:Label></span>
                        </td>
                        <td>
                            <asp:TextBox ID="txtbz" Width="443px" TextMode="MultiLine" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr class="z2">
                        <td class="zt5">
                              退货总金额：     
                        </td>
                        <td>
                            <asp:Label ID="lblReturnTotal" runat="server"></asp:Label>
                        </td>
                        <td class="zt5">
                            
                        </td>
                        <td>
                            
                        </td>
                    </tr>
                    <%--<tr class="z2">
                        <td class="zt5">
                             退款方式：
                        </td>
                        <td colspan="3">
                            <asp:DropDownList ID="DropDownList1" Width="126" runat="server">
                                <asp:ListItem Text="结余款" Value="000" Selected="true"></asp:ListItem>
                                <asp:ListItem Text="其  他" Value="001"></asp:ListItem>
                            </asp:DropDownList>
                        </td>
                    </tr>--%>
                </table>
            </div>
            <div class="menu_bg4">
                <span class="jiacu">商品明细</span>
            </div>
            <div class="juli">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                <asp:DataList ID="DataList1" runat="server" OnItemCommand="DataList1_ItemCommand"
                    OnItemDataBound="DataList1_ItemDataBound" Width="100%">
                    <HeaderTemplate>
                        <tr>
                            <td class="td_left" width="6%">
                                删除</td>
                            <td class="td_left" width="30%">
                                代码名称</td>
                            <td class="td_left" width="6%">
                                颜色</td>
                            <td class="td_left" width="6%">
                                尺码</td>
                            <td class="td_left" width="6%">
                                数量</td>
                            <td class="td_left" width="8%">
                                标准单价</td>
                            <td class="td_left" width="8%">
                                折扣</td>
                            <td class="td_left" width="8%">
                                实际单价</td>
                            <td class="td_left" width="8%">
                                标准金额</td>
                            <td class="td_left" width="8%">
                                实际金额</td>
                            <td class="td_right" width="6%">
                                重量</td>
                        </tr>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <tr>
                            <td class="td_left1" width="6%">
                                <asp:Button ID="btnDelete" runat="server" CssClass="input_button" CommandName="delete"
                                    CommandArgument='<%# Eval("od_id")+"|"+Eval("od_detailid") %>' Text="删除" />
                            </td>
                            <td class="td_left1" width="30%">
                                <asp:HiddenField ID="hdcolor" runat="server" Value='<%# Eval("od_colorcode") %>' />
                                <asp:HiddenField ID="hdsize" runat="server" Value='<%# Eval("od_sizecode") %>' />
                                <span style="display: none;">
                                    <asp:Label ID="lblspdm" runat="server" Text='<%# Eval("od_cmdcode").ToString().Trim() %>'></asp:Label></span>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("od_cmdcode").ToString().Trim()+"  "+Eval("spmc").ToString().Trim() %>'></asp:Label></td>
                            <td class="td_left1" width="6%">
                                <asp:DropDownList ID="color" runat="server" DataTextField="ggmc" DataValueField="ggdm" Enabled="false">
                                </asp:DropDownList>
                            </td>
                            <td class="td_left1" width="6%">
                                <asp:DropDownList ID="size" runat="server" DataTextField="ggmc" DataValueField="ggdm" Enabled="false">
                                </asp:DropDownList>
                            </td>
                            <td class="td_left1" width="6%">
                                <asp:TextBox ID="txtQuantity" runat="server" Text='<%# Eval("od_qty") %>' CssClass="zt7" Width="50"  onkeyup="CountTotal()"></asp:TextBox></td>
                            <td class="td_left2" width="8%">
                                <asp:Label ID="lblSprice" runat="server" Text='<%# Eval("od_sprice").ToString().Trim() %>'></asp:Label>
                            </td>
                            <td class="td_left1" width="8%">
                                <%--<asp:TextBox ID="txtZK" runat="server" Text='<%# Eval("od_disc") %>' CssClass="zt7" Width="50"></asp:TextBox>--%>
                                <asp:Label ID="lblDiscount" runat="server" Text='<%# Eval("od_disc") %>' CssClass="zt7" Width="50"></asp:Label>
                            </td>
                            <td class="td_left2" width="8%">
                                <%--<%# Eval("od_aprice") %>--%>
                                <asp:Label ID="lblAprice" runat="server" Text='<%# Eval("od_aprice") %>' CssClass="zt7" Width="50"></asp:Label>
                            </td>
                            <td class="td_left2" width="8%">
                                <%--<%# Eval("od_samt") %>--%>
                                <asp:Label ID="lblSamt" runat="server" Text='<%# Eval("od_samt") %>' CssClass="zt7" Width="50"></asp:Label>
                            </td>
                            <td class="td_left2" width="8%">
                                <%--<%# Eval("od_aamt") %>--%>
                                <asp:Label ID="lblAamt" runat="server" Text='<%# Eval("od_aamt") %>' CssClass="zt7" Width="50"></asp:Label>
                            </td>
                            <td class="td_right2" width="8%">
                                <asp:Label ID="lblweight" runat="server" Text='<%# Eval("OD_WEIGHT").ToString().Trim() %>'></asp:Label>
                                <span style="display: none;">
                                    <asp:TextBox ID="txtOldQuantity" runat="server" Text='<%# Eval("od_qty") %>' Width="50"></asp:TextBox>
                                    <asp:Label ID="lblOD_ITG" runat="server" Text='<%# Eval("OD_ITG").ToString().Trim() %>'></asp:Label>
                                    <asp:Label ID="lblOD_ADDITG" runat="server" Text='<%# Eval("OD_ADDITG").ToString().Trim() %>'></asp:Label>
                                    <asp:Label ID="lblOD_SPPRICE" runat="server" Text='<%# Eval("OD_SPPRICE").ToString().Trim() %>'></asp:Label>
                                    <asp:Label ID="lblOD_ITGBUY" runat="server" Text='<%# Eval("OD_ITGBUY").ToString().Trim() %>'></asp:Label>
                                    <asp:Label ID="lblOD_ITGPRICE" runat="server" Text='<%# Eval("OD_ITGPRICE").ToString().Trim() %>'></asp:Label>
                                    <input id="hidWeight" type="hidden" runat="server" value='<%# Eval("OD_WEIGHT").ToString().Trim() %>' />
                                    <input id="hidSprice" type="hidden" runat="server" value='<%# Eval("od_sprice").ToString().Trim() %>' />
                                    <input id="hidAprice" type="hidden" runat="server" value='<%# Eval("od_aprice").ToString().Trim() %>' />
                                </span>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:DataList>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
            <br />
            <div class="menu_bg">
                <asp:Button ID="Button1" CssClass="input_button1" runat="server" Text="生成退货单" OnClick="Button1_Click" /></div>
                <input id="hidOrderDetailCount" runat="server" type="hidden" />
                
        </div>
    </form>
</body>
</html>
